package cn.oi.klittle.era.activity.photo.utils;

import java.text.SimpleDateFormat;


/**
 * 视频时长计算
 */
public class KDateUtils {
    private static SimpleDateFormat msFormat = new SimpleDateFormat("mm:ss");

    /**
     * MS turn every minute
     * fixme 转成分钟格式: 00:00
     *
     * @param duration Millisecond 时间，单位秒
     * @return Every minute
     */
    public static String timeParse(long duration) {
        String time = "";
        if (duration > 1000) {
            time = timeParseMinute(duration);
        } else {
            long minute = duration / 60000;
            long seconds = duration % 60000;
            long second = Math.round((float) seconds / 1000);
            if (minute < 10) {
                time += "0";
            }
            time += minute + ":";
            if (second < 10) {
                time += "0";
            }
            time += second;
        }
        return time;
    }

    /**
     * MS turn every minute
     *
     * @param duration Millisecond
     * @return Every minute
     */
    public static String timeParseMinute(long duration) {
        try {
            return msFormat.format(duration);
        } catch (Exception e) {
            e.printStackTrace();
            return "0:00";
        }
    }

    /**
     * 判断两个时间戳相差多少秒
     *
     * @param d
     * @return
     */
    public static int dateDiffer(long d) {
        try {
            long l1 = Long.parseLong(String.valueOf(System.currentTimeMillis()).substring(0, 10));
            long interval = l1 - d;
            return (int) Math.abs(interval);
        } catch (Exception e) {
            e.printStackTrace();
            return -1;
        }
    }

//    /**
//     * 计算两个时间间隔
//     *
//     * @param sTime
//     * @param eTime
//     * @return
//     */
//    public static String cdTime(long sTime, long eTime) {
//        long diff = eTime - sTime;
//        return diff > 1000 ? diff / 1000 + "秒" : diff + "毫秒";
//    }
}
